package de.fhin.mas.agents.navigator.behaviours;

import jade.core.Agent;
import jade.domain.FIPANames;
import jade.domain.FIPAAgentManagement.FailureException;
import jade.domain.FIPAAgentManagement.NotUnderstoodException;
import jade.domain.FIPAAgentManagement.RefuseException;
import jade.lang.acl.ACLMessage;
import jade.proto.AchieveREResponder;
import de.fhin.mas.MASEvents;
import de.fhin.mas.agents.navigator.NavigatorAgent;
import de.fhin.mas.util.MessageUtil;

/**
 * 
 * @author Matthias Wilhelm
 * 
 */
public class ChangeOfLocNecessaryHandler extends AchieveREResponder {
	/**
	 * 
	 */
	private static final long serialVersionUID = 921460383248224790L;

	public ChangeOfLocNecessaryHandler(Agent a) {
		super(a, MessageUtil.buildBasicCommunicationTemplate(
				FIPANames.InteractionProtocol.FIPA_REQUEST,
				MASEvents.CHANGE_OF_LOCATION_NECESSARY.getName(),
				ACLMessage.REQUEST, null));
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected ACLMessage prepareResponse(ACLMessage request)
			throws NotUnderstoodException, RefuseException {

		ACLMessage reply = request.createReply();
		reply.setPerformative(ACLMessage.AGREE);

		return reply;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected ACLMessage prepareResultNotification(ACLMessage request,
			ACLMessage response) throws FailureException {

		((NavigatorAgent) myAgent).randomDrive();

		ACLMessage reply = request.createReply();
		reply.setPerformative(ACLMessage.INFORM);
		reply.setContent("done");

		return reply;
	}

}
